//
//  UIDevice+Hardware.m
//  TestTable
//
//  Created by Inder Kumar Rathore on 19/01/13.
//  Copyright (c) 2013 Rathore. All rights reserved.
//

#import "UIDevice+Hardware.h"
#include <sys/types.h>
#include <sys/sysctl.h>

@implementation UIDevice (Hardware)
- (NSString*)hardwareString {
    size_t size = 100;
    char *hw_machine = malloc(size);
    int name[] = {CTL_HW,HW_MACHINE};
    sysctl(name, 2, hw_machine, &size, NULL, 0);
    NSString *hardware = [NSString stringWithUTF8String:hw_machine];
    free(hw_machine);
    return hardware;
}

/* This is another way of gtting the system info
 * For this you have to #import <sys/utsname.h>
 */

/*
 NSString* machineName
 {
 struct utsname systemInfo;
 uname(&systemInfo);
 return [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
 }
 */

- (Hardware)hardware {
    NSString *hardware = [self hardwareString];
    if ([hardware isEqualToString:@"iPhone1,1"])    return IPHONE_2G;
    if ([hardware isEqualToString:@"iPhone1,2"])    return IPHONE_3G;
    if ([hardware isEqualToString:@"iPhone2,1"])    return IPHONE_3GS;
    if ([hardware isEqualToString:@"iPhone3,1"])    return IPHONE_4;
    if ([hardware isEqualToString:@"iPhone3,2"])    return IPHONE_4;
    if ([hardware isEqualToString:@"iPhone3,3"])    return IPHONE_4_CDMA;
    if ([hardware isEqualToString:@"iPhone4,1"])    return IPHONE_4S;
    if ([hardware isEqualToString:@"iPhone5,1"])    return IPHONE_5;
    if ([hardware isEqualToString:@"iPhone5,2"])    return IPHONE_5_CDMA_GSM;
    if ([hardware isEqualToString:@"iPhone5,3"])    return IPHONE_5C;
    if ([hardware isEqualToString:@"iPhone5,4"])    return IPHONE_5C_CDMA_GSM;
    if ([hardware isEqualToString:@"iPhone6,1"])    return IPHONE_5S;
    if ([hardware isEqualToString:@"iPhone6,2"])    return IPHONE_5S_CDMA_GSM;
    if ([hardware isEqualToString:@"iPhone7,1"])    return IPHONE_6_PLUS;
    if ([hardware isEqualToString:@"iPhone7,2"])    return IPHONE_6;
    if ([hardware isEqualToString:@"iPhone8,1"])    return IPHONE_6S;
    if ([hardware isEqualToString:@"iPhone8,2"])    return IPHONE_6S_PLUS;
    if ([hardware isEqualToString:@"iPhone9,1"])    return IPHONE_7_CDMA;
    if ([hardware isEqualToString:@"iPhone9,3"])    return IPHONE_7_GSM;
    if ([hardware isEqualToString:@"iPhone9,2"])    return IPHONE_7_PLUS_CDMA;
    if ([hardware isEqualToString:@"iPhone9,4"])    return IPHONE_7_PLUS_GSM;
    if ([hardware isEqualToString:@"iPhone8,4"])    return IPHONE_SE;
    if ([hardware isEqualToString:@"iPhone10,1"])   return IPHONE_8_CDMA;
    if ([hardware isEqualToString:@"iPhone10,4"])   return IPHONE_8_GSM;
    if ([hardware isEqualToString:@"iPhone10,2"])   return IPHONE_8_PLUS_CDMA;
    if ([hardware isEqualToString:@"iPhone10,5"])   return IPHONE_8_PLUS_GSM;
    if ([hardware isEqualToString:@"iPhone10,3"])   return IPHONE_X_CDMA;
    if ([hardware isEqualToString:@"iPhone10,6"])   return IPHONE_X_GSM;
    
    
    if ([hardware isEqualToString:@"iPod1,1"])      return IPOD_TOUCH_1G;
    if ([hardware isEqualToString:@"iPod2,1"])      return IPOD_TOUCH_2G;
    if ([hardware isEqualToString:@"iPod3,1"])      return IPOD_TOUCH_3G;
    if ([hardware isEqualToString:@"iPod4,1"])      return IPOD_TOUCH_4G;
    if ([hardware isEqualToString:@"iPod5,1"])      return IPOD_TOUCH_5G;
    
    if ([hardware isEqualToString:@"iPad1,1"])      return IPAD;
    if ([hardware isEqualToString:@"iPad1,2"])      return IPAD_3G;
    if ([hardware isEqualToString:@"iPad2,1"])      return IPAD_2_WIFI;
    if ([hardware isEqualToString:@"iPad2,2"])      return IPAD_2;
    if ([hardware isEqualToString:@"iPad2,3"])      return IPAD_2_CDMA;
    if ([hardware isEqualToString:@"iPad2,4"])      return IPAD_2;
    if ([hardware isEqualToString:@"iPad2,5"])      return IPAD_MINI_WIFI;
    if ([hardware isEqualToString:@"iPad2,6"])      return IPAD_MINI;
    if ([hardware isEqualToString:@"iPad2,7"])      return IPAD_MINI_WIFI_CDMA;
    if ([hardware isEqualToString:@"iPad3,1"])      return IPAD_3_WIFI;
    if ([hardware isEqualToString:@"iPad3,2"])      return IPAD_3_WIFI_CDMA;
    if ([hardware isEqualToString:@"iPad3,3"])      return IPAD_3;
    if ([hardware isEqualToString:@"iPad3,4"])      return IPAD_4_WIFI;
    if ([hardware isEqualToString:@"iPad3,5"])      return IPAD_4;
    if ([hardware isEqualToString:@"iPad3,6"])      return IPAD_4_GSM_CDMA;
    if ([hardware isEqualToString:@"iPad4,1"])      return IPAD_AIR_WIFI;
    if ([hardware isEqualToString:@"iPad4,2"])      return IPAD_AIR_WIFI_GSM;
    if ([hardware isEqualToString:@"iPad4,3"])      return IPAD_AIR_WIFI_CDMA;
    if ([hardware isEqualToString:@"iPad4,4"])      return IPAD_MINI_RETINA_WIFI;
    if ([hardware isEqualToString:@"iPad4,5"])      return IPAD_MINI_RETINA_WIFI_CDMA;
    if ([hardware isEqualToString:@"iPad4,7"])      return IPAD_MINI_3;
    if ([hardware isEqualToString:@"iPad4,8"])      return IPAD_MINI_3;
    if ([hardware isEqualToString:@"iPad4,9"])      return IPAD_MINI_3;
    if ([hardware isEqualToString:@"iPad5,1"])      return IPAD_MINI_4;
    if ([hardware isEqualToString:@"iPad5,2"])      return IPAD_MINI_4;
    if ([hardware isEqualToString:@"iPad5,3"])      return IPAD_AIR_2;
    if ([hardware isEqualToString:@"iPad5,4"])      return IPAD_AIR_2;
    if ([hardware isEqualToString:@"iPad6,3"])      return IPAD_PRO_9_7;
    if ([hardware isEqualToString:@"iPad6,4"])      return IPAD_PRO_9_7;
    if ([hardware isEqualToString:@"iPad6,7"])      return IPAD_PRO_12_9;
    if ([hardware isEqualToString:@"iPad6,8"])      return IPAD_PRO_12_9;
    
    if ([hardware isEqualToString:@"i386"])         return SIMULATOR;
    if ([hardware isEqualToString:@"x86_64"])       return SIMULATOR;
    return NOT_AVAILABLE;
}

- (NSString*)hardwareDescription {
    NSString *hardware = [self hardwareString];
    if ([hardware isEqualToString:@"iPhone1,1"])    return @"iPhone 2G";
    if ([hardware isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
    if ([hardware isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
    if ([hardware isEqualToString:@"iPhone3,1"])    return @"iPhone 4 (GSM)";
    if ([hardware isEqualToString:@"iPhone3,2"])    return @"iPhone 4 (GSM Rev. A)";
    if ([hardware isEqualToString:@"iPhone3,3"])    return @"iPhone 4 (CDMA)";
    if ([hardware isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([hardware isEqualToString:@"iPhone5,1"])    return @"iPhone 5 (GSM)";
    if ([hardware isEqualToString:@"iPhone5,2"])    return @"iPhone 5 (Global)";
    if ([hardware isEqualToString:@"iPhone5,3"])    return @"iPhone 5C (GSM)";
    if ([hardware isEqualToString:@"iPhone5,4"])    return @"iPhone 5C (Global)";
    if ([hardware isEqualToString:@"iPhone6,1"])    return @"iPhone 5S (GSM)";
    if ([hardware isEqualToString:@"iPhone6,2"])    return @"iPhone 5S (Global)";
    if ([hardware isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([hardware isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
    if ([hardware isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
    if ([hardware isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
    if ([hardware isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
    if ([hardware isEqualToString:@"iPhone9,1"])    return @"iPhone 7 (CDMA)";
    if ([hardware isEqualToString:@"iPhone9,3"])    return @"iPhone 7 (GSM)";
    if ([hardware isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus (CDMA)";
    if ([hardware isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus (GSM)";
    if ([hardware isEqualToString:@"iPhone10,1"])   return @"iPhone 8 (A1863/A1906)";
    if ([hardware isEqualToString:@"iPhone10,4"])   return @"iPhone 8 (Global/A1905)";
    if ([hardware isEqualToString:@"iPhone10,2"])   return @"iPhone 8 Plus (A1864/A1898)";
    if ([hardware isEqualToString:@"iPhone10,5"])   return @"iPhone 8 Plus (Global/A1897)";
    if ([hardware isEqualToString:@"iPhone10,3"])   return @"iPhone X (A1865/A1902)";
    if ([hardware isEqualToString:@"iPhone10,6"])   return @"iPhone X (Global/A1901)";
    if ([hardware isEqualToString:@"iPhone11,2"])   return @"iPhone XS";
    if ([hardware isEqualToString:@"iPhone11,4"])   return @"iPhone XS Max";
    if ([hardware isEqualToString:@"iPhone11,6"])   return @"iPhone XS Max";
    if ([hardware isEqualToString:@"iPhone11,8"])   return @"iPhone XR";
    
    if ([hardware isEqualToString:@"iPod1,1"])      return @"iPod Touch (1 Gen)";
    if ([hardware isEqualToString:@"iPod2,1"])      return @"iPod Touch (2 Gen)";
    if ([hardware isEqualToString:@"iPod3,1"])      return @"iPod Touch (3 Gen)";
    if ([hardware isEqualToString:@"iPod4,1"])      return @"iPod Touch (4 Gen)";
    if ([hardware isEqualToString:@"iPod5,1"])      return @"iPod Touch (5 Gen)";
    if ([hardware isEqualToString:@"iPod7,1"])      return @"iPod Touch (6 Gen)";
    
    if ([hardware isEqualToString:@"iPad1,1"])      return @"iPad (WiFi)";
    if ([hardware isEqualToString:@"iPad1,2"])      return @"iPad 3G";
    if ([hardware isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
    if ([hardware isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
    if ([hardware isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
    if ([hardware isEqualToString:@"iPad2,4"])      return @"iPad 2 (WiFi Rev. A)";
    if ([hardware isEqualToString:@"iPad2,5"])      return @"iPad Mini (WiFi)";
    if ([hardware isEqualToString:@"iPad2,6"])      return @"iPad Mini (GSM)";
    if ([hardware isEqualToString:@"iPad2,7"])      return @"iPad Mini (CDMA)";
    if ([hardware isEqualToString:@"iPad3,1"])      return @"iPad 3 (WiFi)";
    if ([hardware isEqualToString:@"iPad3,2"])      return @"iPad 3 (CDMA)";
    if ([hardware isEqualToString:@"iPad3,3"])      return @"iPad 3 (Global)";
    if ([hardware isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
    if ([hardware isEqualToString:@"iPad3,5"])      return @"iPad 4 (CDMA)";
    if ([hardware isEqualToString:@"iPad3,6"])      return @"iPad 4 (Global)";
    if ([hardware isEqualToString:@"iPad4,1"])      return @"iPad Air (WiFi)";
    if ([hardware isEqualToString:@"iPad4,2"])      return @"iPad Air (WiFi+GSM)";
    if ([hardware isEqualToString:@"iPad4,3"])      return @"iPad Air (WiFi+CDMA)";
    if ([hardware isEqualToString:@"iPad4,4"])      return @"iPad Mini Retina (WiFi)";
    if ([hardware isEqualToString:@"iPad4,5"])      return @"iPad Mini Retina (WiFi+CDMA)";
    if ([hardware isEqualToString:@"iPad4,7"])      return @"iPad Mini 3 (WiFi)";
    if ([hardware isEqualToString:@"iPad4,8"])      return @"iPad Mini 3 (Cellular)";
    if ([hardware isEqualToString:@"iPad4,9"])      return @"iPad Mini 3 (Cellular)";
    if ([hardware isEqualToString:@"iPad5,1"])      return @"iPad Mini 4 (WiFi)";
    if ([hardware isEqualToString:@"iPad5,2"])      return @"iPad Mini 4 (Cellular)";
    if ([hardware isEqualToString:@"iPad5,3"])      return @"iPad Air 2 (WiFi)";
    if ([hardware isEqualToString:@"iPad5,4"])      return @"iPad Air 2 (Cellular)";
    if ([hardware isEqualToString:@"iPad6,3"])      return @"iPad Pro 9.7-inch (WiFi)";
    if ([hardware isEqualToString:@"iPad6,4"])      return @"iPad Pro 9.7-inch (Cellular)";
    if ([hardware isEqualToString:@"iPad6,7"])      return @"iPad Pro 12.9-inch (WiFi)";
    if ([hardware isEqualToString:@"iPad6,8"])      return @"iPad Pro 12.9-inch (Cellular)";
    if ([hardware isEqualToString:@"iPad4,7"])      return @"iPad Mini 3";
    if ([hardware isEqualToString:@"iPad4,8"])      return @"iPad Mini 3";
    if ([hardware isEqualToString:@"iPad4,9"])      return @"iPad Mini 3";
    if ([hardware isEqualToString:@"iPad5,1"])      return @"iPad Mini 4";
    if ([hardware isEqualToString:@"iPad5,2"])      return @"iPad Mini 4";
    if ([hardware isEqualToString:@"iPad5,3"])      return @"iPad Air 2";
    if ([hardware isEqualToString:@"iPad5,4"])      return @"iPad Air 2";
    if ([hardware isEqualToString:@"iPad6,3"])      return @"iPad Pro 9.7-inch";
    if ([hardware isEqualToString:@"iPad6,4"])      return @"iPad Pro 9.7-inch";
    if ([hardware isEqualToString:@"iPad6,7"])      return @"iPad Pro 12.9-inch";
    if ([hardware isEqualToString:@"iPad6,8"])      return @"iPad Pro 12.9-inch";
    
    if ([hardware isEqualToString:@"i386"])         return @"Simulator";
    if ([hardware isEqualToString:@"x86_64"])       return @"Simulator";
    
#ifdef DEBUG
    NSLog(@"This is a device which is not listed in this category. Please visit https://github.com/inderkumarrathore/UIDevice-Hardware and add a comment there.");
    NSLog(@"Your device hardware string is: %@", hardware);
#endif
    
    if ([hardware hasPrefix:@"iPhone"]) return @"iPhone";
    if ([hardware hasPrefix:@"iPod"]) return @"iPod";
    if ([hardware hasPrefix:@"iPad"]) return @"iPad";
    return nil;
}

- (NSString*)hardwareSimpleDescription
{
    NSString *hardware = [self hardwareString];
    if ([hardware isEqualToString:@"iPhone1,1"])    return @"iPhone 2G";
    if ([hardware isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
    if ([hardware isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
    if ([hardware isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
    if ([hardware isEqualToString:@"iPhone3,2"])    return @"iPhone 4";
    if ([hardware isEqualToString:@"iPhone3,3"])    return @"iPhone 4";
    if ([hardware isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([hardware isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
    if ([hardware isEqualToString:@"iPhone5,2"])    return @"iPhone 5";
    if ([hardware isEqualToString:@"iPhone5,3"])    return @"iPhone 5C";
    if ([hardware isEqualToString:@"iPhone5,4"])    return @"iPhone 5C";
    if ([hardware isEqualToString:@"iPhone6,1"])    return @"iPhone 5S";
    if ([hardware isEqualToString:@"iPhone6,2"])    return @"iPhone 5S";
    if ([hardware isEqualToString:@"iPhone7,1"])    return @"iPhone 6 Plus";
    if ([hardware isEqualToString:@"iPhone7,2"])    return @"iPhone 6";
    if ([hardware isEqualToString:@"iPhone8,1"])    return @"iPhone 6s";
    if ([hardware isEqualToString:@"iPhone8,2"])    return @"iPhone 6s Plus";
    if ([hardware isEqualToString:@"iPhone8,4"])    return @"iPhone SE";
    if ([hardware isEqualToString:@"iPhone9,1"])    return @"iPhone 7";
    if ([hardware isEqualToString:@"iPhone9,2"])    return @"iPhone 7 Plus";
    if ([hardware isEqualToString:@"iPhone9,3"])    return @"iPhone 7";
    if ([hardware isEqualToString:@"iPhone9,4"])    return @"iPhone 7 Plus";
    if ([hardware isEqualToString:@"iPhone10,1"])   return @"iPhone 8";
    if ([hardware isEqualToString:@"iPhone10,2"])   return @"iPhone 8P";
    if ([hardware isEqualToString:@"iPhone10,3"])   return @"iPhone X";
    if ([hardware isEqualToString:@"iPhone10,4"])   return @"iPhone 8";
    if ([hardware isEqualToString:@"iPhone10,5"])   return @"iPhone 8P";
    if ([hardware isEqualToString:@"iPhone10,6"])   return @"iPhone X";
    if ([hardware isEqualToString:@"iPhone11,2"])   return @"iPhone XS";
    if ([hardware isEqualToString:@"iPhone11,4"])   return @"iPhone XS Max";
    if ([hardware isEqualToString:@"iPhone11,6"])   return @"iPhone XS Max";
    if ([hardware isEqualToString:@"iPhone11,8"])   return @"iPhone XR";
    
    if ([hardware isEqualToString:@"iPod1,1"])      return @"iPod Touch (1 Gen)";
    if ([hardware isEqualToString:@"iPod2,1"])      return @"iPod Touch (2 Gen)";
    if ([hardware isEqualToString:@"iPod3,1"])      return @"iPod Touch (3 Gen)";
    if ([hardware isEqualToString:@"iPod4,1"])      return @"iPod Touch (4 Gen)";
    if ([hardware isEqualToString:@"iPod5,1"])      return @"iPod Touch (5 Gen)";
    if ([hardware isEqualToString:@"iPod7,1"])      return @"iPod Touch (6 Gen)";
    
    if ([hardware isEqualToString:@"iPad1,1"])      return @"iPad";
    if ([hardware isEqualToString:@"iPad1,2"])      return @"iPad";
    if ([hardware isEqualToString:@"iPad2,1"])      return @"iPad 2";
    if ([hardware isEqualToString:@"iPad2,2"])      return @"iPad 2";
    if ([hardware isEqualToString:@"iPad2,3"])      return @"iPad 2";
    if ([hardware isEqualToString:@"iPad2,4"])      return @"iPad 2";
    if ([hardware isEqualToString:@"iPad2,5"])      return @"iPad Mini";
    if ([hardware isEqualToString:@"iPad2,6"])      return @"iPad Mini";
    if ([hardware isEqualToString:@"iPad2,7"])      return @"iPad Mini";
    if ([hardware isEqualToString:@"iPad3,1"])      return @"iPad 3";
    if ([hardware isEqualToString:@"iPad3,2"])      return @"iPad 3";
    if ([hardware isEqualToString:@"iPad3,3"])      return @"iPad 3";
    if ([hardware isEqualToString:@"iPad3,4"])      return @"iPad 4";
    if ([hardware isEqualToString:@"iPad3,5"])      return @"iPad 4";
    if ([hardware isEqualToString:@"iPad3,6"])      return @"iPad 4";
    if ([hardware isEqualToString:@"iPad4,1"])      return @"iPad Air";
    if ([hardware isEqualToString:@"iPad4,2"])      return @"iPad Air";
    if ([hardware isEqualToString:@"iPad4,3"])      return @"iPad Air";
    if ([hardware isEqualToString:@"iPad4,4"])      return @"iPad Mini Retina";
    if ([hardware isEqualToString:@"iPad4,5"])      return @"iPad Mini Retina";
    if ([hardware isEqualToString:@"iPad4,7"])      return @"iPad Mini 3";
    if ([hardware isEqualToString:@"iPad4,8"])      return @"iPad Mini 3";
    if ([hardware isEqualToString:@"iPad4,9"])      return @"iPad Mini 3";
    if ([hardware isEqualToString:@"iPad5,1"])      return @"iPad Mini 4";
    if ([hardware isEqualToString:@"iPad5,2"])      return @"iPad Mini 4";
    if ([hardware isEqualToString:@"iPad5,3"])      return @"iPad Air 2";
    if ([hardware isEqualToString:@"iPad5,4"])      return @"iPad Air 2";
    if ([hardware isEqualToString:@"iPad6,3"])      return @"iPad Pro 9.7-inch";
    if ([hardware isEqualToString:@"iPad6,4"])      return @"iPad Pro 9.7-inch";
    if ([hardware isEqualToString:@"iPad6,7"])      return @"iPad Pro 12.9-inch";
    if ([hardware isEqualToString:@"iPad6,8"])      return @"iPad Pro 12.9-inch";
    
    if ([hardware isEqualToString:@"i386"])         return @"Simulator";
    if ([hardware isEqualToString:@"x86_64"])       return @"Simulator";
    
#ifdef DEBUG
    NSLog(@"This is a device which is not listed in this category. Please visit https://github.com/inderkumarrathore/UIDevice-Hardware and add a comment there.");
    NSLog(@"Your device hardware string is: %@", hardware);
#endif
    
    if ([hardware hasPrefix:@"iPhone"]) return @"iPhone";
    if ([hardware hasPrefix:@"iPod"]) return @"iPod";
    if ([hardware hasPrefix:@"iPad"]) return @"iPad";
    
    return nil;
}


- (float)hardwareNumber:(Hardware)hardware {
    switch (hardware) {
        case IPHONE_2G:          return 1.1f;
        case IPHONE_3G:          return 1.2f;
        case IPHONE_3GS:         return 2.1f;
        case IPHONE_4:           return 3.1f;
        case IPHONE_4_CDMA:      return 3.3f;
        case IPHONE_4S:          return 4.1f;
        case IPHONE_5:           return 5.1f;
        case IPHONE_5_CDMA_GSM:  return 5.2f;
        case IPHONE_5C:          return 5.3f;
        case IPHONE_5C_CDMA_GSM: return 5.4f;
        case IPHONE_5S:          return 6.1f;
        case IPHONE_5S_CDMA_GSM: return 6.2f;
        case IPHONE_6_PLUS:      return 7.1f;
        case IPHONE_6:           return 7.2f;
        case IPHONE_7_GSM:       return 9.3f;
        case IPHONE_6S:          return 8.1f;
        case IPHONE_6S_PLUS:     return 8.2f;
        case IPHONE_SE:          return 8.4f;
        case IPHONE_7_CDMA:      return 9.1f;
        case IPHONE_7_PLUS_CDMA: return 9.2f;
        case IPHONE_7_PLUS_GSM:  return 9.4f;
        case IPHONE_8_CDMA:      return 10.1f;
        case IPHONE_8_GSM:       return 10.4f;
        case IPHONE_8_PLUS_CDMA: return 10.2f;
        case IPHONE_8_PLUS_GSM:  return 10.5f;
        case IPHONE_X_CDMA:      return 10.3f;
        case IPHONE_X_GSM:       return 10.6f;
            
        case IPOD_TOUCH_1G:    return 1.1f;
        case IPOD_TOUCH_2G:    return 2.1f;
        case IPOD_TOUCH_3G:    return 3.1f;
        case IPOD_TOUCH_4G:    return 4.1f;
        case IPOD_TOUCH_5G:    return 5.1f;
            
        case IPAD:    return 1.1f;
        case IPAD_3G:    return 1.2f;
        case IPAD_2_WIFI:    return 2.1f;
        case IPAD_2:    return 2.2f;
        case IPAD_2_CDMA:    return 2.3f;
        case IPAD_MINI_WIFI:    return 2.5f;
        case IPAD_MINI:    return 2.6f;
        case IPAD_MINI_WIFI_CDMA:    return 2.7f;
        case IPAD_3_WIFI:    return 3.1f;
        case IPAD_3_WIFI_CDMA:    return 3.2f;
        case IPAD_3:    return 3.3f;
        case IPAD_4_WIFI:    return 3.4f;
        case IPAD_4:    return 3.5f;
        case IPAD_4_GSM_CDMA:    return 3.6f;
        case IPAD_AIR_WIFI:    return 4.1f;
        case IPAD_AIR_WIFI_GSM:    return 4.2f;
        case IPAD_AIR_WIFI_CDMA:    return 4.3f;
        case IPAD_MINI_RETINA_WIFI:    return 4.4f;
        case IPAD_MINI_RETINA_WIFI_CDMA:    return 4.5f;
        case IPAD_AIR2_WIFI: return 5.3f;
            
        case IPAD_MINI_3: return 4.3f;
        case IPAD_MINI_4: return 5.1f;
        case IPAD_AIR_2: return 5.3f;
        case IPAD_PRO_9_7: return 6.3f;
        case IPAD_PRO_12_9: return 6.7f;
            
            
        case SIMULATOR:    return 100.0f;
        case NOT_AVAILABLE:    return 200.0f;
    }
    return 200.0f; //Device is not available
}

- (BOOL)isCurrentDeviceHardwareBetterThan:(Hardware)hardware {
    float otherHardware = [self hardwareNumber:hardware];
    float currentHardware = [self hardwareNumber:[self hardware]];
    return currentHardware >= otherHardware;
}

- (NSString *)currentPixelLevel {
    NSString *hardwareSimpleDescription = [self hardwareSimpleDescription];
    if ([hardwareSimpleDescription isEqualToString:@"iPhone 4S"]) {
        return @"PX_LEVEL_1";
    }
    
    if ([hardwareSimpleDescription isEqualToString:@"iPhone 5"] || [hardwareSimpleDescription isEqualToString:@"iPhone 5C"] || [hardwareSimpleDescription isEqualToString:@"iPhone 5S"] || [hardwareSimpleDescription isEqualToString:@"iPhone SE"]) {
        return @"PX_LEVEL_2";
    }
    
    if ([hardwareSimpleDescription isEqualToString:@"iPhone 6"] || [hardwareSimpleDescription isEqualToString:@"iPhone 6s"] || [hardwareSimpleDescription isEqualToString:@"iPhone 7"] || [hardwareSimpleDescription isEqualToString:@"iPhone 8"]) {
        return @"PX_LEVEL_3";
    }

    if ([hardwareSimpleDescription isEqualToString:@"iPhone 6 Plus"] || [hardwareSimpleDescription isEqualToString:@"iPhone 6s Plus"] || [hardwareSimpleDescription isEqualToString:@"iPhone 7 Plus"] || [hardwareSimpleDescription isEqualToString:@"iPhone 8P"]) {
        return @"PX_LEVEL_4";
    }
    
    if ([hardwareSimpleDescription isEqualToString:@"iPhone X"]) {
        return @"PX_LEVEL_5";
    }
    
    return @"PX_DEFAULT";
}


- (BOOL)isJailbroken {
    
    NSArray *paths = @[@"/Applications/Cydia.app",
                       @"/private/var/lib/apt/",
                       @"/private/var/lib/cydia",
                       @"/private/var/stash"];
    for (NSString *path in paths) {
        if ([[NSFileManager defaultManager] fileExistsAtPath:path]) return YES;
    }
    
    FILE *bash = fopen("/bin/bash", "r");
    if (bash != NULL) {
        fclose(bash);
        return YES;
    }
    NSString *cydiaPath = @"/Applications/Cydia.app";
    
    NSString *aptPath = @"/private/var/lib/apt/";
    
    if ([[NSFileManager defaultManager] fileExistsAtPath:cydiaPath])
        
    {
        return YES;
    }
    
    if ([[NSFileManager defaultManager] fileExistsAtPath:aptPath])
        
    {
        return YES;
    }
   
    return NO;
}

- (BOOL)isIPhoneXSeries {
    BOOL iPhoneXSeries = NO;
    if (UIDevice.currentDevice.userInterfaceIdiom != UIUserInterfaceIdiomPhone) {
        return iPhoneXSeries;
    }
    
    if ([[[[UIDevice currentDevice] hardwareSimpleDescription] lowercaseString] containsString:@"iphone x"]) {
        iPhoneXSeries = YES;
    }
    
    if (@available(iOS 11.0, *)) {
        UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
        if (mainWindow.safeAreaInsets.bottom > 0.0) {
            iPhoneXSeries = YES;
        }
    }
    
    return iPhoneXSeries;
}

@end
